package com.htgd.gardenexpo.controller;


import com.htgd.gardenexpo.entity.CommonResult;
import com.htgd.gardenexpo.entity.GeConDailyDataDeck;
import com.htgd.gardenexpo.entity.GeConLeisureDataDeck;
import com.htgd.gardenexpo.service.IGeConDailyDataDeckService;
import com.htgd.gardenexpo.service.IGeConDailyDataDeckTaskService;
import com.htgd.gardenexpo.service.IGeConLeisureDataDeckService;
import com.htgd.gardenexpo.utils.TokenUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 * 日常甲板数据 前端控制器
 * </p>
 *
 * @author author
 * @since 2025-04-03
 */
@RestController
@RequestMapping("/api/dailyDataDeck")
@Api(tags = "日常甲板数据")
@Slf4j
public class GeConDailyDataDeckController {

    @Autowired
    private IGeConDailyDataDeckService geConDailyDataDeckService;

    @Autowired
    private IGeConDailyDataDeckTaskService geConDailyDataDeckTaskService;

    @PostMapping(value = "/add")
    @ApiOperation("添加")
    public CommonResult add(@RequestBody GeConDailyDataDeck geConDailyDataDeck) {
        log.info("日常甲板数据-添加：{}",geConDailyDataDeck);
        return geConDailyDataDeckService.add(geConDailyDataDeck);
    }

    @PutMapping(value = "/updateStatus")
    @ApiOperation("更新任务状态")
    public CommonResult updateStatus(@RequestParam(value = "taskId")String taskId) {
        log.info("日常甲板数据-更新任务状态：{}",taskId);
        return geConDailyDataDeckTaskService.updateStatus(taskId);
    }

    @GetMapping(value = "/getTaskDetails")
    @ApiOperation("获取任务详情")
    public CommonResult getTaskDetails(@RequestParam(value = "taskId") String taskId) {
        log.info("日常甲板数据-获取任务详情：{}",taskId);
        return geConDailyDataDeckService.getTaskDetails(taskId);
    }

    @GetMapping("/getMyData")
    @ApiOperation("智慧起跑线获取我的数据")
    public CommonResult getMyData(HttpServletRequest request) {
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("智慧起跑线获取我的数据：{}",openId);
        return geConDailyDataDeckService.getMyData(openId);
    }

    @GetMapping("/getMySportsRecordData")
    @ApiOperation("智慧起跑线获取我的运动记录")
    public CommonResult getMyData(@RequestParam(defaultValue = "1") Integer pageNum,
                                  @RequestParam(defaultValue = "10") Integer pageSize,
                                  HttpServletRequest request) {
        String accessToken = request.getHeader("Access_token");
        String openId = TokenUtil.getUsernameFromToken(accessToken);
        log.info("智慧起跑线获取我的运动记录：{},{},{}",openId,pageNum,pageSize);
        return geConDailyDataDeckService.getMySportsRecordData(openId,pageNum,pageSize);
    }

}
